<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%
	/**
	 功能名称:修改年度功能
	 @author:
	 **/
%>
<%
String path = request.getContextPath();
%>
<html>
  <head>
  <title>修改年度</title>
  <link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
  <script src="<%=path%>/dwr/engine.js"></script>
  <script src="<%=path%>/dwr/util.js"></script>
  <script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
  <script language="javascript" src="<%=path %>/js/syAjax.js"></script>
  <script type="text/javascript">
  		String.prototype.len=function(){		
		    var len = 0;
		    for (var i = 0; i < this.length; i++) {      
		        if (this.charCodeAt(i) > 255 || this.charCodeAt(i)<0) len += 2; else len ++;      
		    }      
			return len;
		}
     function getSchoolTermCallBack(year) {
        if(year){
        chkyearResult=true;
        }
       } 
          
     function isSchoolTermValueExsit(){
     var value=document.getElementById("yearValue").value;
     shiyueDwr.isYearValueExsit(value,getSchoolTermCallBack);
     }
      
      var chkyearResult=false;
      function doUpdate(){
      var yearId=document.getElementById("yearId").value;
	  var yearName=document.getElementById("yearName");
	  var yearValue=document.getElementById("yearValue");
	  if(yearName.value==""){
	    alert("年度名称不能为空！");
	    yearName.focus();
	    return;
	  }else if(yearValue.value==""){
	    alert("年度不能为空！");
	    yearValue.focus();
	    return;
	  }else if(!/^\d{4}-\d{4}$/.test(yearValue.value)){
	    alert("你输入的年度格式不符合要求！");
	    yearValue.select();
        return;
	  
	  }else{
	    if(yearValue.value!='${requestScope.YearById.yearValue }'){
	    isSchoolTermValueExsit();
	    if(!chkyearResult){
	    alert("该年度存在，请确保年度唯一！");
        yearValue.select();
        return;
	    }
	    }
	  }
	    syAjax.request("post","updateYearyearAndSchoolTermAction.action","year.name="+yearName.value+"&year.yearValue="+yearValue.value+"&year.yearId="+yearId,{success:initSuccessResult,fail:onFail,type:'plain'});
	  }
	
	function initSuccessResult(data){
		window.returnValue=data;
		window.close();
	}
	
	</script>
  </head>
  <body bgcolor="#ECE9D8">
  <form action="" method="post">
    <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8">&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td>
  </tr>
  <tr>
    <td height="12" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25%" height="30" align="right" class="f_6"><span class="f_11">* </span>年度名称：</td>
        <td width="75%" align="left"><input type="text" name="year.name" value="${requestScope.YearById.name }" maxlength="25" id="yearName" /></td>
      </tr>
      <tr>
        <td height="30" align="right" class="f_6"><span class="f_11">*</span> 年度：</td>
        <td align="left">
        <input type="text" name="year.yearValue" value="${requestScope.YearById.yearValue }" id="yearValue"/>
        <input type="hidden" name="year.yearId" value="${requestScope.YearById.yearId }" id="yearId"/>
        </td>
      </tr>
      <tr>
        <td height="20" align="right" class="f_6">&nbsp;</td>
        <td align="left" valign="top" class="f_2">年度格式参照：2012-2013</td>
      </tr>
  
    

     
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="55" align="center" valign="middle" bgcolor="#ECE9D8"><input type="button" value="提 交" onclick="doUpdate();"/></td>
  </tr>
</table>
</form>
  </body>
</html>
